#!/usr/bin/env python

import os
import sys

searchString=sys.argv[1]
print "Search for %s" %searchString

for i in os.listdir("."):

	if not os.path.isdir(i):
		continue

	if ".svn" in i:
		continue

	os.chdir(i)
	for f in os.listdir("."):
		if ".tex" not in f or ".tex.bak" in f:
			continue
		for line in open(f):
			if searchString in line:
				doIt="kwrite "+f
				os.system(doIt)
				break
	os.chdir("..")


